package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.PulleyJoint;
import com.badlogic.gdx.physics.box2d.joints.PulleyJointDef;

public class PulleyJointFactory extends JointFactory<PulleyJointFactory>
{
	private static final PulleyJointDef _initialDef = new PulleyJointDef();
	
	private PulleyJointDef _def;
	
	public PulleyJointFactory()
	{
		this(false);
	}
	
	PulleyJointFactory(boolean managed)
	{
		super(managed);
		_def = new PulleyJointDef();
		setDef(_def);
	}
	
	public PulleyJointFactory localAnchorA (Vector2 v)
	{
		_def.localAnchorA.set(v);
		return this;
	}
	
	public PulleyJointFactory localAnchorA (float x, float y)
	{
		_def.localAnchorA.set(x, y);
		return this;
	}
	
	public PulleyJointFactory groundAnchorA(Vector2 a)
	{
		_def.groundAnchorA.set(a);
		return this;
	}
	
	public PulleyJointFactory groundAnchorB(Vector2 a)
	{
		_def.groundAnchorB.set(a);
		return this;
	}
	
	public PulleyJointFactory lengthA(float l)
	{
		_def.lengthA = l;
		return this;
	}
	
	public PulleyJointFactory lengthB(float l)
	{
		_def.lengthB = l;
		return this;
	}
	
	public PulleyJointFactory ratio(float r)
	{
		_def.ratio = r;
		return this;
	}
	
	public PulleyJoint create(World w)
	{
		return (PulleyJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.groundAnchorA.set(_initialDef.groundAnchorA);
		_def.groundAnchorB.set(_initialDef.groundAnchorB);
		_def.lengthA = _initialDef.lengthA;
		_def.lengthB = _initialDef.lengthB;
		_def.localAnchorA.set(_initialDef.localAnchorA);
		_def.localAnchorB.set(_initialDef.localAnchorB);
		_def.ratio = _initialDef.ratio;		
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
